package cn.lee.wechat.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.zhouyafeng.itchat4j.api.WechatTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api("系统状态相关的API")
@RestController
@RequestMapping(value="/sys")
public class StatusController {
	/**
	 * logger
	 */
	private static final Logger logger = LogManager.getLogger(StatusController.class.getName());
	
	/**
	 * 查询微信是否在线
	 * @return 在线返回TRUE，不在线返回FALSE
	 */
	@ApiResponses({
		@ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=400,message="请求参数没填好")
	})
	@ApiOperation(value="查询微信是否在线",notes="查询用户是否在线，在线返回TRUE，不在线返回FALSE")
	@RequestMapping(value="/status",method=RequestMethod.GET)
	public String getStatus(){
		boolean wechatStatus = WechatTools.getWechatStatus();
		logger.info("查询微信登陆状态");
		if(wechatStatus==Boolean.TRUE){
			logger.info("查询微信在线状态，结果--> 在线");
			return Boolean.TRUE.toString();
		}else{
			logger.info("查询微信在线状态，结果--> 不在线");
			return Boolean.FALSE.toString();
		}
	}
}
